<?php
loadTemp("admin/models/class/classheader.php");
?>
<script type="text/javascript">
$(document).ready(function(){
	loadAdminTopItem();
	activeAdminTopItem("s_c_editclass");
});
</script>
<?php checkAdminPermission("admin.class.edit_class","admin.class.*");?>
<!-- Start -->
<script type="text/javascript">
$(document).ready(function(){
	bindAjaxForm($("#form_edit_class"),s_editclass_onSuccess,s_editclass_onError,"admin_di");
	bindAjaxForm($("#form_edit_search"),s_editclass_onSuccess,s_editclass_onError,"admin_di");
	$("#form_edit_class").hide();
});
function s_editclass_onSuccess(data){
	s_editclass_operatedone(data.code,data.message,data.data);
}
function s_editclass_onError(data){
	console.log(data);
	s_editclass_operatedone(-101,"服务器返回了未知的数据，请上报管理员",data.responseText);
}
function s_editclass_operatedone(id,message,data){
	if(id==-101){
		showMessage("s_editclass_message",-101,message+"<br><br><pre>"+data+"</pre>");
		return;
	}
	if(id!=0&&id!=3){
		showMessage("s_editclass_message",id,message);
	}
	if(id==0){
		showMessage("s_editclass_message",id,message);
	}
	if(data.op=="reset"){
		$("#form_edit_class").find(".f").val("");
		$(".s_master_selecter").find(".s_master_headImage").attr("src","");
		$(".s_master_selecter").find(".s_master_name").html("");
		$(".s_master_selecter").find(".s_master_uid").attr("value","");
		$("#form_edit_search").show();
		$("#form_edit_class").hide();
		$("#s_edit_search").val("");
	}
	if(data.op=="master_search"){
		$(".s_master_selecter").find(".s_master_headImage").attr("src",data.card.head_image_path);
		$(".s_master_selecter").find(".s_master_name").html(data.card.name);
		$(".s_master_selecter").find(".s_master_uid").attr("value",data.card.uid);
		$("#master_account").val("");
		$("#nowmaster").html("新的班主任：")
	}
	if(data.op=="class_search"){
		$(".s_master_selecter").find(".s_master_headImage").attr("src",data.card.head_image_path);
		$(".s_master_selecter").find(".s_master_name").html(data.card.name);
		$(".s_master_selecter").find(".s_master_uid").attr("value",data.card.uid);
		setRadiobox(data["class"]["enable"], "l_");
		$("#admission_year").val(data["class"]["admission_year"]);
		$("#s_edit_classid").val(data["class"]["classid"]);
		$("#s_edit_displayname").val(data["class"]["displayname"]);
		$("#s_edit_introduce").val(data["class"]["description"]);
		$("#form_edit_search").hide();
		$("#form_edit_class").show();
	}
}
function s_doc_search(a){
	if(a==""){
		return;
	}
	ajaxRequest("account="+a,"admin.php?mod=class&ajax=true&op=search_master",s_editclass_onSuccess,s_editclass_onError);
	
}
</script>
<div class="s_admin_in_container">
	<h2 class="ui dividing header">编辑班级</h2>
	<div class="ui message">
		<div class="header">小提示</div>
		<ul class="list">
			<li>这里是班级编辑模块</li>
			<li>你可以在这里编辑班级</li>
		</ul>
	</div>
	<div class="ui message hidden" id="s_editclass_message"></div>
	<form class="ui form" url="admin.php?mod=class&ajax=true&op=search_edit_class" id="form_edit_search">
		<div class="ui action fluid input">
			<div class="ui left icon input">
				<input type="text" name="classid" placeholder="请输入你要编辑的班级的班级id" id="s_edit_search">
				<i class="users icon"></i>
			</div>
			<button class="ui button submit" type="submit">确定</button>
		</div>
	</form>
	<form class="ui form" url="admin.php?mod=class&ajax=true&op=edit_class" id="form_edit_class">
		<div class="field">
			<label>班级id</label>
			<div class="field disabled">
				<input id="s_edit_classid" class="f" type="text" name="classid" placeholder="班级id不能和现有的重复，推荐年号+班级号，诸如1701（17届1班）">
			</div>
			<label>展示名称</label>
			<div class="field">
				<input id="s_edit_displayname" class="f" type="text" name="displayname" placeholder="班级的展示名称，诸如 2017级1班">
			</div>
			<label>班级介绍</label>
			<div class="field">
				<input id="s_edit_introduce" class="f" type="text" name="introduce" placeholder="班级介绍">
			</div>
			<label>入学年份</label>
			<div class="field">
				<input id="admission_year" class="f" type="text" name="admission_year" placeholder="入学年份的四位数字，例：2019">
			</div>
			<label>该班级还未毕业：</label>
			<div class="inline fields">
				<div class="field">
					<div class="ui radio checkbox">
						<input type="radio" name="enable" id="l_true" value="1" class="hidden">
						<label>是</label>
					</div>
				</div>
				<div class="field">
					<div class="ui radio checkbox">
						<input type="radio" name="enable" id="l_false" value="0" class="hidden">
						<label>否</label>
					</div>
				</div>
			</div>
			<div class="field inline s_master_selecter">
				<label class="nowmaster">现有班主任：</label>
				<input class="s_master_uid" name="master" type="hidden">
				<img class="ui avatar image s_master_headImage">
				<span class="s_master_name"></span>
			</div>
			<div class="ui action fluid input s_master_searcher">
				<label>指定新的班主任（如需更改请在这里输入账号）：</label>
				<div class="ui left icon input">
					<input type="text" name="account" id="master_account" placeholder="请输入班主任的账号" onBlur="s_doc_search($('#master_account').val());">
					<i class="users icon"></i>
				</div>
			</div>
		</div>
		<div class="ui error message"></div>
		<button type="submit" class="ui submit button" tabindex="0">保存更改</button>
	</form>
</div>
